#include "serveroverviewwidget.h"
#include <util/version.h>
using namespace mongo;
ServerOverviewWidget::ServerOverviewWidget(QWidget *parent) :
    QWidget(parent)
{
    setupUi(this);
}

void ServerOverviewWidget::initServerOverview(mongo::DBClientConnection &clientConnect)
{
    serverAddressEdit->setText(QString(clientConnect.getServerAddress().c_str()));
    MessagingPort& msgPort=clientConnect.port();
    unsigned int port=msgPort.remotePort();
    portEdit->setText(tr("%1").arg(port));
    numberOfConnectionEdit->setText(tr("%1").arg(DBClientConnection::getNumConnections()));

    lazyKillCursorEdit->setText(QString(clientConnect.getLazyKillCursor()?"true":"false"));

    stringLongEdit->setText(QString(clientConnect.toStringLong().c_str()));

    mongo::ConnectionString::ConnectionType connecttionType=clientConnect.type();
    switch(connecttionType)
    {
        case mongo::ConnectionString::INVALID:
            connectionTypeEdit->setText(QString("Invalid"));
            break;
        case mongo::ConnectionString::MASTER:
            connectionTypeEdit->setText(QString("Master"));
            break;
        case mongo::ConnectionString::PAIR:
            connectionTypeEdit->setText(QString("Pair"));
            break;
        case mongo::ConnectionString::SET:
            connectionTypeEdit->setText(QString("Set"));
            break;
        case mongo::ConnectionString::SYNC:
            connectionTypeEdit->setText(QString("Sync"));
            break;
    }
    mongodVersionEdit->setText(QString(mongodVersion().c_str()));
    systemInfoEdit->setText(QString(mongo::sysInfo().c_str()));
}
